home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / AOCE Sample Code / PowerTalk Access Modules / Sample SMSAM / SampleSMSAM Source / BuildingBlocks / Utilities.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-28  |  4.0 KB  |  116 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        Utilities.h
  3.  
  4.     Copyright:    © 1991-1994 by Apple Computer, Inc.
  5.                 All rights reserved.
  6.  
  7.     Part of the AOCE Sample SMSAM Package.  Consult the license
  8.     which came with this software for your specific legal rights.
  9.  
  10. */
  11.  
  12.  
  13.  
  14. #ifndef __UTILITIES__
  15. #define __UTILITIES__
  16.  
  17. #ifndef __IOSTREAM__
  18. #include "iostream.h"
  19. #endif
  20.  
  21. #ifndef __OCE__
  22. // #include "OCE.h"
  23. #endif
  24.  
  25. struct RString;
  26.  
  27. const short kFolder = 0;
  28. const short kFile = 1;
  29. const short kNotFileOrFolder = -1;
  30.  
  31. //
  32. //    FILE RELATED FUNCTIONS
  33. //    ======================
  34. //
  35.  
  36. // GetIndexHFSInfo:            For a given vRefNum, dirRefNum and index, return the refNum, filename and
  37. //                            whether kFolder,kFile, or kNotFileOrFolder.  If the index = 0 then return
  38. //                            the information for file in the directory with theName
  39. OSErr GetIndexHFSInfo(short index, short vRefNum, long dirRefNum, const StringPtr theName);
  40. OSErr GetIndexHFSInfo(short index, short vRefNum, long dirRefNum, long& refNum, const StringPtr theName, short& isFile);
  41.  
  42.  
  43. //    CreatFolderIfItDoesntExist:    Given a folder name and its parent folder's dirID create a folder
  44. //                                if it doesn't exist. Return the dirID of the folder.
  45. long CreateFolderIfItDoesntExist(short vRefNum, long parentDir, const StringPtr folderName);
  46.  
  47.  
  48. //    Given a folder id this call deletes all the visible files in a folder
  49. void DeleteFilesInFolder(short vRefNum, long folderID);
  50. void DeleteFilesInFolderOlderThan ( short vRefNum, long dirID, unsigned long deleteFilesBeforeDateTime);
  51.  
  52.  
  53. //    GetDirIDForFolder:    Return the dirID for a folder, given the vRefNum of the disk and the folder
  54. //                        name.  If the folder does not exist, return 0 for the dirID.
  55. long GetDirIDForFolder(short vRefNum, long dirID, const StringPtr folderName);
  56.  
  57.  
  58. //    ForceFinderToUpdateFolder:     Given a vRefNum and dirID, force the Finder to flush any cached info
  59. //                                for the folder by touching the modification date for this folder.
  60. OSErr ForceFinderToUpdateFolder(short vRefNum, long dirID);
  61.  
  62. //
  63. //    Move a file named fileName on the volume vRefNum from the directory sourceDirID to
  64. //    the directory destinationDirID.
  65. //
  66. OSErr MoveHFSFile(short vRefNum, long sourceDirID, const StringPtr fileName, long destinationDirID);
  67.  
  68. //
  69. //    min and max functions
  70. //
  71. inline long min(long a, long b) { return (a>b)?b:a; };
  72. inline long longmin(long a, long b) { return (a>b)?b:a; };
  73. inline short shortmin(long a, long b) { return (a>b)?b:a; };
  74.  
  75. inline long max(long a, long b) { return (a>b)?a:b; };
  76. inline short shortmax(short a, short b) { return (a>b)?a:b; };
  77. inline long longmax(long a, long b) { return (a>b)?a:b; };
  78.  
  79. inline between (long x, long low, long high) { return ( (x < low) ? low : ( ( x > high) ? high : x) ); };
  80. inline shortbetween (short x, short low, short high) { return ( (x < low) ? low : ( ( x > high) ? high : x) ); };
  81. inline longbetween (long x, long low, long high) { return ( (x < low) ? low : ( ( x > high) ? high : x) ); };
  82.  
  83.  
  84. //    This macro 'references' a variable, so that a '# warning:  variable not used' warning is not
  85. //    generated during a compile.  This macro should not cause any code to be generated.
  86. #ifndef __UNUSED__
  87. #define unused(x) ((void) &x)
  88. #define __UNUSED__
  89. #endif
  90.  
  91. /*-----------------------------------------------------------
  92. -    MatchResString:        Determines if a string exists in a
  93. -                        STR# list and returns the index
  94. -
  95. -        theStr:            string to search for
  96. -        startIndex:        inclusive start of the search
  97. -        endIndex:        inclusive end of search
  98. -        resID:            STR# res id to look in
  99. -
  100. -        returns:        the index of the string
  101. ------------------------------------------------------------
  102. */
  103.  
  104. extern short MatchResString(const StringPtr theStr, short startIndex, short endIndex, short resID);
  105. extern pascal void BLJDUc2rString (const char* cStr, short charSet, RString *rStr, unsigned short rStrLength);
  106. extern ostream& DumpHex (ostream& s, const void *p, unsigned long size);
  107. extern void GetRezMessage(short rezId, short problemIndex, RString& message);
  108. extern unsigned long NowDateTime(void);    // gets date/time in seconds
  109.  
  110. //
  111. //    Clear out the structure to all zero's.
  112. //
  113. #define    CLEARBLOCK(x)    memset(&x,0,sizeof(x));
  114.  
  115. #endif    // __UTILITIES__
  116.